﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Search_AlarmFeedbackForm
 * 类型：       控制层
 * 功能说明：   报警反馈页面
 * 作者：       徐傲明
 * 创建日期：   2008/02/22
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using log4net;
using Shpm.App.Commons.Utils;
using Shpm.System.Validator;
using Shpm.System.Web.Control;
using Shpm.App.Search.Dao;
using Shpm.App.Search.Bean;
using Shpm.App.Master.Bean;
using Shpm.App.Master.Dao;

public partial class App_Search_AlarmFeedbackForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //接收参数
            string receiveNo = Convert.ToString(Request.QueryString["RECEIVE_NO"]);

            if (!string.IsNullOrEmpty(receiveNo))
            {
                this.ViewState["RECEIVE_NO"] = receiveNo;
            }
            else
            {
                this.ViewState["RECEIVE_NO"] = null;
            }
        }

    }

    void Page_PreRender(object sender, EventArgs e)
    {
        AlarmFeedbackBean bean = new AlarmFeedbackBean();
        AlarmFeedbackDao dao = new AlarmFeedbackDao();
        PersonTrainBean dataBean = new PersonTrainBean();
        PersonTrainDao dataDao = new PersonTrainDao();
        //SysUserManager manager = new SysUserManager(Context);
        //string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        //获取主键
        bean.RowId = Convert.ToInt32(this.ViewState["RECEIVE_NO"]);
        //查询数据
        bean = dao.GetAlarmFeedbackInfo(bean);

        //置页面数据
        if (bean != null)
        {   //保安姓名
            dataBean.EmployeeId = bean.EnsureId;
            dataBean = dataDao.GetEmployeeName(dataBean);
            



            if (dataBean != null) txtBaoanName.Text = dataBean.EmployeeName;

            //管家姓名
            dataBean = new PersonTrainBean();
            dataBean.EmployeeId = bean.ChamberlainId;
            dataBean = dataDao.GetEmployeeName(dataBean);
            if (dataBean !=null)txtButlerName.Text = dataBean.EmployeeName;

            //领导姓名
            dataBean = new PersonTrainBean();
            dataBean.EmployeeId = bean.LeadId;
            dataBean = dataDao.GetEmployeeName(dataBean);
            if (dataBean != null) txtLeadName.Text = dataBean.EmployeeName;

            //备注
            dataBean = new PersonTrainBean();
            dataBean.EmployeeId = bean.MemoId;
            dataBean = dataDao.GetEmployeeName(dataBean);
            if (dataBean != null) txtRemarkName.Text = dataBean.EmployeeName;

        
            txtBaoanId.Text = bean.EnsureId;
            txtBaoanMemo.Text = bean.EnsureMemo;
            txtButlerId.Text = bean.ChamberlainId;
            txtButlerMemo.Text = bean.ChamberlainMemo;
            txtLeadId.Text = bean.LeadId;
            txtLeadMemo.Text = bean.LeadMemo;
            txtRemarkId.Text = bean.MemoId;
            txtRemarkMemo.Text = bean.MemoMemo;
        }

    }

    /*名称： btnSave_Click
     *功能： 登记反馈信息
     *参数： 
     *返回： 无
     *说明： 无
     */
    protected void btnSave_Click(object sender, EventArgs e)
    {
        AlarmFeedbackBean bean = new AlarmFeedbackBean();
        AlarmFeedbackDao dao = new AlarmFeedbackDao();

        //取得登录者ID
        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        //取得主键
        bean.RowId = Convert.ToInt32(this.ViewState["RECEIVE_NO"]);
        //取得数据
        bean = dao.GetAlarmFeedbackInfo(bean);

        //监测保安ID
        if (!string.IsNullOrEmpty(txtBaoanId.Text))
        {
            if (checkEmpId(txtBaoanId.Text) == false)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                              HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0032").ToString().Replace("{0}", this.txtBaoanId.Text);
                return;
            }
        }

        //监测管家ID
        if (!string.IsNullOrEmpty(txtButlerId.Text))
        {
            if (checkEmpId(txtButlerId.Text) == false)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                              HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0032").ToString().Replace("{0}", this.txtButlerId.Text);
                return;
            }
        }

        //监测领导ID
        if (!string.IsNullOrEmpty(txtLeadId.Text))
        {
            if (checkEmpId(txtLeadId.Text) == false)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                              HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0032").ToString().Replace("{0}", this.txtLeadId.Text);
                return;
            }
        }

        //监测备注ID
        if (!string.IsNullOrEmpty(txtRemarkId.Text))
        {
            if (checkEmpId(txtRemarkId.Text) == false)
            {
                ((Design_MasterPage)this.Master).InfoMessage =
                              HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0032").ToString().Replace("{0}", this.txtRemarkId.Text);
                return;
            }
        }

        if (bean == null)//数据库无此条数据时
        {
            bean = new AlarmFeedbackBean();
            bean.RowId = Convert.ToInt32(this.ViewState["RECEIVE_NO"]);
            bean.EnsureId = txtBaoanId.Text;
            bean.EnsureMemo = txtBaoanMemo.Text;
            bean.ChamberlainId = txtButlerId.Text;
            bean.ChamberlainMemo = txtButlerMemo.Text;
            bean.LeadId = txtLeadId.Text;
            bean.LeadMemo = txtLeadMemo.Text;
            bean.MemoId = txtRemarkId.Text;
            bean.MemoMemo = txtRemarkMemo.Text;
            bean.UserId = userId;
            //新建数据
            dao.InsertAlarmFeedback(bean);
        }
        else//数据库有此条数据时
        {
            bean.RowId = Convert.ToInt32(this.ViewState["RECEIVE_NO"]);
            bean.EnsureId = txtBaoanId.Text;
            bean.EnsureMemo = txtBaoanMemo.Text;
            bean.ChamberlainId = txtButlerId.Text;
            bean.ChamberlainMemo = txtButlerMemo.Text;
            bean.LeadId = txtLeadId.Text;
            bean.LeadMemo = txtLeadMemo.Text;
            bean.MemoId = txtRemarkId.Text;
            bean.MemoMemo = txtRemarkMemo.Text;
            bean.UserId = userId;
            //更新成功
            dao.UpdAlarmFeedback(bean);
        }
        //提示成功
        Response.Write("<script language=JavaScript>" +
                 "alert('" + HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0037").ToString().Replace("{0}", "登记") + "');</script>");
       

    }

    /*名称： checkEmpId
     *功能： 监测员工ID
     *参数： 
     *返回： bool
     *说明： 无
     */
    private bool checkEmpId(string eStr)
    {
        EmployeeBean eBean = new EmployeeBean();
        EmployeeDao eDao = new EmployeeDao();
        eBean.EmployeeId = eStr;
        eBean = eDao.GetEmployee(eBean);
        if (eDao.GetEmployee(eBean) == null)
            return false;
        return true;
    }
}
